﻿Public Class HOUSETYPE

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Dim PROVIDER_MASHOUSETYPE As New PROVIDERSCLASS

    Private Sub HOUSETYPE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridhousetype()

        DesignForm(Me)
        DesignGrid(MASHOUSETYPEGrid)

        PROVIDER_MASHOUSETYPE.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridhousetype()
        Dim objSelectDatamashousetype As New mashousetype
        Dim MASHOUSETYPE As DataTable
        MASHOUSETYPE = connect.GetTable(objSelectDatamashousetype.selectMashousetype_)
        MASHOUSETYPEGrid.PrimaryGrid.DataSource = MASHOUSETYPE
    End Sub

    Private Sub MASHOUSETYPEGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASHOUSETYPEGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสประเภท").Value() IsNot DBNull.Value Then
            HOUSETYPEIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสประเภท").Value()
        Else
            HOUSETYPEIDTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ประเภทเคหสถาน").Value() IsNot DBNull.Value Then
            HOUSETYPETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ประเภทเคหสถาน").Value()
        Else
            HOUSETYPETxt.Text = ""
        End If
        addHousetype.Enabled = False
    End Sub

    Private Sub addHousetype_Click_1(sender As Object, e As EventArgs) Handles addHousetype.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASHOUSETYPE.PADD_ = True Then
                Dim objInsertData As New mashousetype
                objInsertData.HUTDESC_ = HOUSETYPETxt.Text
                objInsertData.insertMashousetypeData()

                SelectDatagridhousetype()

                HOUSETYPEIDTxt.Text = ""
                HOUSETYPETxt.Text = ""
            Else
                MsgBox(PROVIDER_MASHOUSETYPE.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editHousetype_Click_1(sender As Object, e As EventArgs) Handles editHousetype.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASHOUSETYPE.PUPD_ = True Then
                Dim editStat As Integer
                editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลประเภทที่อยู่ดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                If editStat = 1 Then
                    Dim objEditData As New mashousetype
                    objEditData.housetypeID_ = CInt(HOUSETYPEIDTxt.Text)
                    objEditData.HUTDESC_ = HOUSETYPETxt.Text
                    objEditData.editMashousetypeData()

                    SelectDatagridhousetype()

                    HOUSETYPEIDTxt.Text = ""
                    HOUSETYPETxt.Text = ""
                End If
            Else
                MsgBox(PROVIDER_MASHOUSETYPE.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("mashousetype")
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL("mashousetype")
        nextform.ShowDialog()
    End Sub
End Class